var count:Number=0;
var countMax:Number=100000;
var loop:Number=0;

var unitGap:Number=1000;
var noticeEventArr:Array=new Array();

function regNoticeEvent(evt:Object)
{
	// evt:Object
	// type - dispatchEvent type
	// gap - dispatchEvent interval
	// count - event inner count
	noticeEventArr.push(evt);
}

function removeNoticeEvent(type:String)
{
	for (var i=0; i<noticeEventArr.length; i++)
	{
		if (noticeEventArr[i].type==type)
		{
			noticeEventArr[i]=null;
			delete noticeEventArr[i];
			return;
		}
	}
}

function forward()
{
	// Packages.log("Timer.forward", "debug");
	loop=setInterval(this, "playback", unitGap, this);
}

function playback()
{
	// Packages.log("Timer.playback", "debug");
	
	if (count<countMax)
	{
		checkNoticeEvent();
		count++;
	}
	else 
	{
		count=0;
		clearInterval(loop);
	}
}

function checkNoticeEvent()
{
	// Packages.log("Timer.checkNoticeEvent: "+count, "debug");
	for (var i=0; i<noticeEventArr.length; i++)
	{
		noticeEventArr[i].count++;
		if (noticeEventArr[i].count==noticeEventArr[i].gap)
		{
			noticeEventArr[i].count=0;
			Packages.system.mlf.GateKeeper.dispatchMessage({type:noticeEventArr[i].type});
		}
	}
}

forward();
// Packages.system.display.Timer.forward();